import { _decorator, Component, Node,tween,Vec3,v3} from 'cc';
import {GameMain} from "./GameMain";
import Platform from "./Platform";
const { ccclass, property } = _decorator;

@ccclass('RetryUI')
export class RetryUI extends Component {

    public targetNode:Node=null;
    public inited:boolean=false;

    onLoad()
    {
        this.init();
        Platform.createInsertAd();
    }

    start() {

    }

    update(deltaTime: number)
    {
        
    }

    public init()
    {
        if(this.inited)
            return;
        this.targetNode=this.node.getChildByName("window");
        this.inited=true;
    }

    public show()
    {
        if(this.node.active)
            return;

        if(Platform.isOV())
        {
            Platform.createOVCustomAd();
        }

        this.init();
        this.node.active=true;
        this.targetNode.setScale(0.3, 0.3,1);
        tween(this.targetNode)
            .to(0.3,{scale:Vec3.ONE}, { easing: 'backOut' })
            .start();
    }

    public close()
    {
        tween(this.targetNode).to(0.2,{scale:v3(0.5, 0.5, 0.5)}).call(()=>{
            this.node.active=false;
            GameMain.instance.prepareRetry();
        }).start();
    }


    public onRestartLevelClicked()
    {
        this.close();
    }
}

